//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.baidu.lbsapi.auth.tracesdk;

import android.content.Context;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import org.json.JSONException;
import org.json.JSONObject;

class e {
    private Context a;
    private List b = null;
    private e.a c = null;

    protected e(Context var1) {
        this.a = var1;
    }

    protected void a(HashMap var1, String[] var2, e.a var3) {
        this.b = this.a(var1, var2);
        this.c = var3;
        (new Thread(new f(this))).start();
    }

    private void a(String var1) {
        if(var1 == null) {
            var1 = "";
        }

        JSONObject var2 = null;

        try {
            if(!(var2 = new JSONObject(var1)).has("status")) {
                var2.put("status", -1);
            }
        } catch (JSONException var4) {
            var2 = new JSONObject();

            try {
                var2.put("status", -1);
            } catch (JSONException var3) {
                var3.printStackTrace();
            }
        }

        if(this.c != null) {
            this.c.a(var2.toString());
        }

    }

    private void a(List var1) {
        com.baidu.lbsapi.auth.tracesdk.a.a("syncConnect start Thread id = " + String.valueOf(Thread.currentThread().getId()));
        if(var1 != null && var1.size() != 0) {
            ArrayList var2 = new ArrayList();

            int var3;
            for(var3 = 0; var3 < var1.size(); ++var3) {
                com.baidu.lbsapi.auth.tracesdk.a.a("syncConnect resuest " + var3 + "  start!!!");
                HashMap var4 = (HashMap)var1.get(var3);
                g var5;
                if((var5 = new g(this.a)).a()) {
                    String var8 = var5.a(var4);
                    if(var8 == null) {
                        var8 = "";
                    }

                    com.baidu.lbsapi.auth.tracesdk.a.a("syncConnect resuest " + var3 + "  result:" + var8);
                    var2.add(var8);

                    try {
                        JSONObject var10;
                        if((var10 = new JSONObject(var8)).has("status")) {
                            int var11 = var10.getInt("status");
                            if(var11 == 0) {
                                com.baidu.lbsapi.auth.tracesdk.a.a("auth end and break");
                                this.a(var8);
                                return;
                            }
                        }
                    } catch (JSONException var6) {
                        com.baidu.lbsapi.auth.tracesdk.a.a("continue-------------------------------");
                    }
                } else {
                    com.baidu.lbsapi.auth.tracesdk.a.a("Current network is not available.");
                    var2.add(ErrorMessage.a("Current network is not available."));
                }

                com.baidu.lbsapi.auth.tracesdk.a.a("syncConnect end");
            }

            com.baidu.lbsapi.auth.tracesdk.a.a("--iiiiii:" + var3 + "<><>paramList.size():" + var1.size() + "<><>authResults.size():" + var2.size());
            if(var1.size() > 0 && var3 == var1.size() && var2.size() > 0 && var3 == var2.size() && var3 - 1 > 0) {
                try {
                    JSONObject var9;
                    if((var9 = new JSONObject((String)var2.get(var3 - 1))).has("status") && var9.getInt("status") != 0) {
                        com.baidu.lbsapi.auth.tracesdk.a.a("i-1 result is not 0,return first result");
                        this.a((String)var2.get(0));
                        return;
                    }

                    return;
                } catch (JSONException var7) {
                    this.a(ErrorMessage.a("JSONException:" + var7.getMessage()));
                }
            }

        } else {
            com.baidu.lbsapi.auth.tracesdk.a.c("syncConnect failed,params list is null or size is 0");
        }
    }

    private List a(HashMap var1, String[] var2) {
        ArrayList var3 = new ArrayList();
        if(var2 != null && var2.length > 0) {
            for(int var8 = 0; var8 < var2.length; ++var8) {
                HashMap var9 = new HashMap();
                Iterator var10 = var1.keySet().iterator();

                while(var10.hasNext()) {
                    String var7 = ((String)var10.next()).toString();
                    var9.put(var7, var1.get(var7));
                }

                var9.put("mcode", var2[var8]);
                var3.add(var9);
            }
        } else {
            HashMap var4 = new HashMap();
            Iterator var5 = var1.keySet().iterator();

            while(var5.hasNext()) {
                String var6 = ((String)var5.next()).toString();
                var4.put(var6, var1.get(var6));
            }

            var3.add(var4);
        }

        return var3;
    }

    interface a {
        void a(String var1);
    }

    static List a(e arg1) {
        return arg1.b;
    }

    static void a(e arg0, List arg1) {
        arg0.a(arg1);
    }
}
